home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / crobots5 / watchdog.r
Text File  |  1987-03-09  |  2KB  |  67 lines

  1. /* WATCHDOG.R     */
  2. /*                */
  3. /* Strategies:    */
  4. /*                */
  5. /*  Movement: Square pattern as close to the border as possible            */
  6. /*      to maximize the amount of time the robot moves at top speed.       */
  7. /*                                                                         */
  8. /*  Attack: Check for enemy and fire in one direction. Then increment      */
  9. /*         the direction 90 degrees for next attack().                     */
  10. /*                                                                         */
  11. /*  Spin: Attack the Corner sitters. Spin axis of attack 45 deg.           */
  12. /*                                                                         */
  13. /*  B. Sanguinet                                                           */
  14. /*
  15. /*                */
  16.  
  17. int range;
  18. int angle;
  19. int cangle;
  20. int resolution;
  21.  
  22. /* main */
  23. main(){
  24.   int border;
  25.   angle=5;            /* Change offset angle to allow robot to lead shots. */
  26.   cangle=45;          
  27.   resolution=5;       /* Change firing precision.   */
  28.   border=100;         /* Change movement border.    */
  29.  while (1) {
  30.  
  31.     drive (180,100);                 /* go west, young robot */
  32.     attack();                        /* cuts down on needless oscillation */ 
  33.     while (loc_x()>border && speed() > 0 ) attack();  /* Keep-a-goin */
  34.     drive (180,0);                                    /* STOP */
  35.     while (speed() > 50) spin();                      /* wait */
  36.  
  37.     drive (90,100);         /* north */
  38.     attack(); 
  39.     while (loc_y()<1000-border && speed() > 0 ) attack();
  40.     drive (90,0);
  41.     while (speed() > 50) spin();   
  42.  
  43.     drive (0,100);         /* east  */
  44.     attack(); 
  45.     while (loc_x()<1000-border && speed() > 0 ) attack();
  46.     drive (0,0);
  47.     while (speed() > 50) spin();
  48.  
  49.     drive (270,100);       /* south */
  50.     attack(); 
  51.     while (loc_y()>border && speed() > 0 ) attack();
  52.     drive (270,0);
  53.     while (speed() > 50) spin();
  54.  
  55.  };                        /* forever */
  56.  
  57. }
  58. attack(){  
  59.      if ((range=scan((angle+=90),resolution)) > 0 && range <=700 )
  60.       while (! cannon(angle,range)); 
  61.     }
  62.  
  63. spin(){  
  64.      if ((range=scan((cangle+=90),resolution)) > 0 && range <=700 ) cannon(cangle,range); 
  65.     }
  66.   
  67.